package com.rede.didiok.admin.restapi.admin;

import java.util.List;

import javax.annotation.Resource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.common.dto.ReportOption;
import com.rede.didiok.common.dto.community.CommunityReportDto;
import com.rede.didiok.common.dto.rank.RankReportDto;
import com.rede.didiok.common.dto.user.ReportDto;
import com.rede.didiok.common.exception.ThrowableUtils;
import com.rede.didiok.common.feign.CommunityFeignClient;
import com.rede.didiok.common.feign.RankFeignClient;
import com.rede.didiok.common.feign.UserFeignClient;
import com.rede.didiok.common.validator.group.GetList;

/**
 * 举报接口 RestApi
 *
 * @author Rede
 * @date 2023-09-04
 */
@RestController
@RefreshScope
@RequestMapping("/admin/report")
@Api(value = "举报相关接口", tags = {"举报相关接口"})
@Slf4j
public class ReportRestApi {

    @Resource
    UserFeignClient userFeignClient;
    @Resource
    RankFeignClient rankFeignClient;
    @Resource
    CommunityFeignClient communityFeignClient;

    @ApiOperation(value = "获取举报列表", notes = "获取举报列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody ReportDto reportDto, BindingResult result) {

        ThrowableUtils.checkParamArgument(result);
        return userFeignClient.getReportPageList(reportDto);
    }

    @ApiOperation(value = "获取举报列表", notes = "获取举报列表", response = String.class)
    @PostMapping("/rank/getList")
    public String getRankReportList(@Validated({GetList.class}) @RequestBody RankReportDto reportDto, BindingResult result) {

        ThrowableUtils.checkParamArgument(result);
        return rankFeignClient.getReportPageList(reportDto);
    }

    @ApiOperation(value = "获取举报列表", notes = "获取举报列表", response = String.class)
    @PostMapping("/community/getList")
    public String getCommunityReportList(@Validated({GetList.class}) @RequestBody CommunityReportDto reportDto, BindingResult result) {

        ThrowableUtils.checkParamArgument(result);
        return communityFeignClient.getReportPageList(reportDto);
    }

    @ApiOperation(value = "批量删除举报列表", notes = "批量删除举报列表", response = String.class)
    @PostMapping("/deleteBatch")
    public String deleteBatch(@RequestBody List<String> reportUidList) {
        return userFeignClient.batchDeleteReport(reportUidList);
    }

    /**
     * 获取举报信息
     *
     * @param reportOption
     * @return
     */
    @ApiOperation(value = "获取举报信息", notes = "获取举报信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键词", required = false),
            @ApiImplicitParam(name = "currentPage", value = "当前页数", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数目", required = true)
    })
    @PostMapping("/list")
    public String list(@RequestBody ReportOption reportOption) {
        return userFeignClient.queryListByContent(reportOption);
    }

    /**
     * 处理举报信息
     *
     * @param reportOption
     * @return
     */
    @ApiOperation(value = "处理举报信息", notes = "处理举报信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportContentUid", value = "被举报稿件Uid", required = true),
            @ApiImplicitParam(name = "reportType", value = "举报的稿件类型", required = true),
            @ApiImplicitParam(name = "progress", value = "处理状态", required = true),
            @ApiImplicitParam(name = "reportUid", value = "举报记录的Uid", required = false)
    })
    @PostMapping("/handle")
    public String getReportByUserUid(@RequestBody ReportOption reportOption) {
        return userFeignClient.handleReport(reportOption.getReportContentUid(), reportOption.getReportType(), reportOption.getReportUid(), reportOption.getProgress());
    }
}
